# -*- coding: utf-8 -*-
"""
类也是对象，type是元类，创建类的类
"""
from abc import ABCMeta

from common import trace
import collections.abc



class Person:

    @trace
    def __init__(self, name=None, **kwargs):
        self.name = name

    def hi(self):
        print('hi~~~~~~~~~~~~~')


def say(self):
    return "my name is {}".format(self.name)


Male = type('Male', (Person,), {"name": "vincent", "age": 30, "say": say})


def person_test():
    person = Person('vincent', age=30)
    p2 = Male()
    print(p2.name, p2.age, '\n', p2.say())
    p2.hi()
    print(p2.__dict__)


class MetaClass(type):
    @trace
    def __new__(cls, *args, **kwargs):
        return super().__new__(cls, *args, **kwargs)

    @trace
    def __init__(cls, *args, **kwargs):
        cls.name = "MyUser"
        super().__init__(*args, **kwargs)


class BaseClass:
    name = 'BaseClass'
    pass


class User(BaseClass, metaclass=MetaClass):
    """
    如果User类对象没有父类，默认是由type元类创建,即： class User(metaclass=type)，
    如果有父类，则向上找父类的metaclass来创建
    """


def user_tet():
    user = User()
    print(User.name, user.name)


if __name__ == '__main__':
    # person_test()
    user_tet()
